/**
 * 
 */
package com.raowb.common.base.entitys;

import java.beans.Transient;
import java.util.List;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonIgnore;

import cn.hutool.core.util.ReflectUtil;
import com.raowb.common.util.StringUtil;

/**
 * @Description: tree实体
 * @author: raowb
 * @date 2018年8月6日
 */
public abstract class BaseTreeEntity extends BaseOrderedEntity {

	/**
	 * 
	 */
	protected static final long serialVersionUID = 1L;

	/*
	 * 层级ID
	 */
	protected String hierarchy;

	protected Long parentId;

	protected String parentName;

	/**
	 * 下级
	 */
	@TableField(exist = false)
	protected List<?> childList;

	// /**
	// * 上级
	// */
	//@TableField(exist=false)
	//protected T parent;

	public String getHierarchy() {
		if (StringUtil.isBlank(hierarchy)) {
			if (getId() == null) {
				return null;
			} else {
				return ("x" + getId() + "x");
			}
		} else {
			return hierarchy;
		}
	}

	public void setHierarchy(String hierarchy) {
		this.hierarchy = hierarchy;
	}

	public Long getParentId() {
		return parentId;
	}

	public void setParentId(Long parentId) {
		this.parentId = parentId;
	}

	@SuppressWarnings("unchecked")
	@Transient
	public List<BaseTreeEntity> getTreeChildList() {
		return (List<BaseTreeEntity>) ReflectUtil.getFieldValue(this, "childList");
	}

	@Transient
	public void setTreeeChildList(List<? extends BaseTreeEntity> childList) {
		ReflectUtil.setFieldValue(this, "childList", childList);
	}

	public String getParentName() {
		return parentName;
	}

	public void setParentName(String parentName) {
		this.parentName = parentName;
	}

	/**
	 * 
	* @Title: getName
	* @Description: 名称
	* @return    设定文件
	* @return String    返回类型
	* @throws
	 */
	public abstract String getName();

}
